#include "stack.h"

Stack *StackInit() //生成空栈
{
    Stack *s;
    s=(Stack *)malloc(sizeof(Stack));
    if(!s)
    return NULL;
    s->top=-1;
    return s;
}

int StackEmpty(Stack *s) //判空
{
    if(s->top==-1)
    return 1;
    else
    return 0;
}

int StackPush(Stack *s,char a) //入栈
{
    if(s->top==MAXSIZE-1)
    return 0;//栈满则无法入栈
    s->top++;
    s->data[s->top]=a;
    return 1;

}

int StackPop(Stack *s,char a) //出栈,将栈顶元素赋给a
{
    if(s->top==-1)
    return 0;//栈空则无法出栈
    a=s->data[s->top];
    //printf("a=%c\n",a);
    s->top--;
    return 1;

}

char StackTop(Stack *s) //取栈顶元素，但不出栈(与判空配合使用)
{
   return s->data[s->top];
}
